import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../theme/theme_color.dart';

class ActPubLishBottomView extends StatelessWidget {
  Function? leftAction; //预览
  Function? rightAction; //发布
  bool isHiddenLeftAction = false;
  String leftName = '预览';
  String rightName = '发布';
  Color? rightColor;

  ActPubLishBottomView(
      {this.leftName = '预览',
      this.rightName = '发布',
      this.isHiddenLeftAction = false,
      Key? key,
      this.leftAction,
      this.rightAction,
      this.rightColor})
      : super(key: key);
  double bottomBtnLeft = 31.w;
  double bottomBtnRight = 29.w;
  double bottomBtnHeight = 50.w;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        children: [
          Container(
            height: 0.5,
            color: ThemeColor.lineColor,
          ),
          Container(
            color: Colors.white,
            height: 84.w,
            margin: EdgeInsets.only(left: 31.w, right: 29.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Offstage(
                   offstage:isHiddenLeftAction,
                  child: getBottomBtnView(
                      name: leftName,
                      titleColor: ThemeColor.appColor,
                      sendAction: leftAction),
                ),
                getBottomBtnView(
                    name: rightName,
                    bgColor: rightColor ?? ThemeColor.appColor,
                    titleColor: Colors.white,
                    sendAction: rightAction),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget getBottomBtnView({
    String name = '',
    Color? bgColor,
    Color? borderColor,
    Color? titleColor,
    Function? sendAction,
  }) {
    double bottomBtnWidth = (1.sw - bottomBtnLeft - bottomBtnRight - 5) / 2.0;
    return GestureDetector(
      onTap: () {
        if (sendAction != null) {
          sendAction();
        }
      },
      child: Container(
        width: bottomBtnWidth,
        height: bottomBtnHeight,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(bottomBtnHeight / 2.0),
            color: bgColor,
            border:
                Border.all(color: bgColor ?? ThemeColor.appColor, width: 1)),
        child: Text(
          name,
          style: TextStyle(
              fontSize: 18, color: titleColor, fontWeight: FontWeight.w600),
        ),
      ),
    );
  }
}
